<div class="_top">
    <div class="_top_left">
        <a class="icon-menu" event-click="{{'$Event.show_menu'}}"></a>
        <a class="icon-home" href="{{bus_loginer.url}}/mobile.main.html#default/main"></a>
    </div>
    <div class="_top_right">
    </div>
</div>
<div class="_menu {{TopPrivate&&'focus'}}">
    <a event-click="{{'$Event.show_menu'}}" href="{{bus_loginer.url}}/mobile.main.html#default/main">
        <div class="_menu_item">
            首页
        </div>
    </a>
    <a event-click="{{'$Event.show_menu'}}" href="{{bus_loginer.url}}/mobile.main.html#default/goods_list?id=3">
        <div class="_menu_item">
            全部商品
        </div>
    </a>
    <a event-click="{{'$Event.show_menu'}}" href="{{bus_loginer.url}}/mobile.main.html#default/tags">
        <div class="_menu_item">
            商品分类
        </div>
    </a>
    <a href="{{bus_loginer.url}}/mobile.main.html#default/storeinfo" event-click="{{'$Event.show_menu'}}">
        <div class="_menu_item">
            店铺信息
        </div>
    </a>
    
</div>
{{#if loginer}}
<div class="_menublock {{TopPrivate&&'focus'}} {{TopUser&&'focus'}}" event-click="{{'$Event.block_close'}}"></div>
<div class="_menu {{TopUser&&'focus'}}">
    <a href="mobile.personal.html">
        <div class="_menu_item">个人中心</div>
    </a>
    <a event-click="{{'$Event.user_login_out'}}">
        <div class="_menu_item">注销</div>
    </a>
</div>
{{/if}}
<div class="_topblock"></div>






<!-- 背景 -->
{{#if bus_info.config.is_use_bg_img}} {{#if bus_info.config.is_bg_img_alpha}}
<div class="themeimgblock" style="position: fixed;width: 100%;height:100%;top:0;left:0;background-color: rgba(255,255,255,0.6);z-index: -1;"></div>
{{/if}}
<img style="display:block;position: fixed;width: 100%;height: 100%;z-index: -2;top:0;left: 0;" src="{{bus_info.config.using_bg_img}}{{#if bus_info.config.is_bg_img_blur}}?imageMogr2/blur/10x10{{/if}}">{{/if}}

<script type="text/vm">
    function (vm) {
        require(["common","coAjax","href","eventManager"], function(jSouper,coAjax,href,eventManager) {
            //注销功能
            App.set("$Event.user_login_out", function() {
                coAjax.get(appConfig.user.login_out_url,function () {
                    App.set("loginer", null);
                    if (href.isUser()) {
                        href.toLogin();
                    }
                });
            });

            
            function _check_collect_bus (collectBus) {
                var is_collect = true;
                if (jSouper.indexOf(collectBus,appConfig.bus_id)===-1) {
                    is_collect = false;
                }
                App.set("$Cache.is_collect_current_bus",is_collect)
            };
            eventManager.on("getLoginer",function () {
                //校验是否已经收藏过此商家
                var collectBus = App.get("loginer.collectBus")||[];
                _check_collect_bus(collectBus);
            });
            
            ;(window.coAjaxLoginUser = function(succ_cb){
        
                //获取登陆用户的信息
                /*
                 * 管理员相关的页面无需登录
                 */
                var no_user_login_pages = {
                    "/admin-beta.html": 1,
                    "/admin-login.html": 1
                }
                if (no_user_login_pages[location.pathname]) {
                    return;
                }
                console.log("获取登陆者信息……", location.pathname);
                /*
                 * 获取登录者信息
                 */
                coAjax.get(appConfig.user.loginer, function(data) {
                    console.log("登录者信息：", data.result);
                    userInfo = data.result;
                    App.set("loginer", userInfo);
                    //触发相关事件
                    eventManager.fire("getLoginer");
                    succ_cb&&succ_cb();
                }, function(errorCode) {
                    var muse_login_pages = {
                            "#default/sign_in": 1,
                            "#default/cart": 1
                        }
                        //未登录，不可进入个人页，强制跳转到登录页
                    if (muse_login_pages[location.pathname]) {
                        href.toLogin();
                    }
                });
            })();
            

            App.set("$Event.user_collect_bus",function () {
                if (App.get("$Cache.is_collect_current_bus")) {
                    coAjax["delete"](appConfig.user.collectBus_remove,{
                        bus_id:appConfig.bus_id
                    },function (result) {
                        alert("已取消店铺收藏");
                        // App.set('$Cache.is_collect_current_bus',false);
                        _check_collect_bus(result.result);
                    },function (errorCode,xhr,errorMsg) {
                        // alert("error",errorMsg)
                        _check_collect_bus(App.get("loginer.collectBus"));
                    });
                }else{
                    coAjax.post(appConfig.user.collectBus_add,{
                        bus_id:appConfig.bus_id
                    },function (result) {
                        alert("success","店铺收藏成功");
                        // App.set('$Cache.is_collect_current_bus',true);
                        _check_collect_bus(result.result);
                    },function (errorCode,xhr,errorMsg) {
                        // alert("error",errorMsg)
                        _check_collect_bus(App.get("loginer.collectBus"));
                    });
                }
            });

            
            App.set('$Event.show_menu',function(){
                App.set('TopUser',false);
                App.model.toggle('TopPrivate');
                var i=1;
                var t=setInterval(function(){
                    if (App.get('TopPrivate')) {
                        if (i>3) {
                            App.set('TopPrivate','');
                            clearInterval(t);
                        }else{
                            i+=1;;
                        }
                    }else{
                        clearInterval(t);
                    };
                },1000);
            });
            
            App.set('$Event.loginer_show',function(){
                App.set('TopPrivate',false);
                App.model.toggle('TopUser');
                var i=1;
                var t=setInterval(function(){
                    if (App.get('TopUser')) {
                        if (i>3) {
                            App.set('TopUser',false);
                            clearInterval(t);
                        }else{
                            i+=1;;
                        }
                    }else{
                        clearInterval(t);
                    };
                },1000);
            });

            App.set('$Event.block_close',function(){
                clearInterval(t);
                App.set('TopPrivate',false);
                App.set('TopUser',false);
            });
        });
    }
</script>
